home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / modem / modem-hardware.frm.z / modem-hardware.frm
Encoding:
Text File  |  1997-07-30  |  9.1 KB  |  346 lines

  1. #!/usr/bin/perl5
  2. #
  3. # modem-hardware.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: modem-hardware.frm,v 1.29 1997/06/19 22:26:01 shotes Exp $
  21.  
  22. # The following actions are taken to reconfigure modem hardware:
  23. # - port turned "off" in /etc/inittab
  24. # - telinit q command issued to reinitialize port
  25. # - fix-modem configuration script is run
  26. # - Devices file is edited (for dial-out or both)
  27. # - device is given uucp ownership (for dial-out or both)
  28. # - action field of /etc/inittab is updated (for dial-in or both)
  29. #
  30. # To determine current modem configurations, the following steps
  31. # are taken:
  32. # - to determine mode, first check inittab file.  if status=off,
  33. #    assume dial-out, if status=on check for existing ACU line
  34. #    in /etc/uucp/Devices.  if line exists it is both, otherwise
  35. #    assume dial-in.  got that?                                
  36. # - for dial-out or dial-in/dial-out, existing "ACU" line with proper
  37. #    port label gives modem and speed.  for dial-in only, I know of
  38. #    no way to get modem or speed.
  39. #
  40. # Note: this script requires the existence of the file 
  41. # /usr/OnRamp/etc/modem.trans to operate correctly
  42.  
  43. require "/usr/OnRamp/lib/OnRamp.pm";
  44.  
  45. $confI = "/etc/inittab";
  46. $confD = "/etc/uucp/Devices";
  47. $translate = "/usr/OnRamp/etc/modem.trans";
  48. $dummy = "/etc/uucp/Devices.tmp";
  49. $myname = "modem-hardware.cgi";
  50. $title = "Modem Configuration";
  51.  
  52. print "Content-type: text/html\n\n";
  53. &title_block($title);
  54.  
  55. &get_fields;
  56.  
  57. &get_modemList;
  58.  
  59. $help = $document_root . $ENV{"SCRIPT_NAME"};
  60. $help =~ s/cgi$/hlp/;
  61. exec $help if ($fld{'help'} eq "Help");
  62.  
  63. if ($fld{'doit'} eq 'Ok') {
  64.     if ($fld{'enable1'} eq 'Yes') { 
  65.     &reconfigure(1);
  66.     $message = "Port 1 has been reconfigured.";
  67.     }
  68.     if ($fld{'enable2'} eq 'Yes') { 
  69.     &reconfigure(2);
  70.     $message .= "  Port 2 has been reconfigured."; 
  71.     }
  72.     if (!$message) { $message = qq|To reconfigure a given port, click "Yes"
  73.             for the appropriate port under "Reconfigure".|; }
  74. }
  75.  
  76. &getCurrentStatus;
  77.  
  78. if (-d "/etc/uucp") { &generic; }
  79. else {
  80.     &header_block($title);
  81.     print "<i>Modem software not installed.  Install subsystem
  82.         </i><b>eoe.sw.uucp</b><i> from the distribution CD.</i>";
  83. }
  84.  
  85. sub error {
  86.     &error_block($_[0]);
  87.     &generic;
  88.     exit 0;
  89. }
  90.  
  91. sub get_modemList {
  92.     open(IN,"< $translate");
  93.     while(<IN>) { 
  94.     @items = split(/:/);
  95.     push(@modemList,$items[1]);
  96.     }
  97.     close(IN);
  98. }
  99.  
  100. sub reconfigure {
  101.     $num = $_[0];
  102.  
  103.     $switch = "";
  104.     &turnOffPort($num);
  105.     system("/sbin/telinit", "q");
  106.     if ($fld{'dial_out'.$num} eq 'Yes') {
  107.     $switch = "o"; 
  108.     &editDevice($num);
  109.     $expr = "chown uucp /dev/ttyd" . $num;
  110.     eval($expr);
  111.     if ($fld{'speed'.$num} > 2400) { 
  112.         $expr = "chown uucp /dev/ttyf" . $num; 
  113.     } else { $expr = "chown uucp /dev/ttym" . $num; }
  114.     eval($expr);
  115.     } else { &deleteDevice($num); }
  116.     if ($fld{'dial_in'.$num} eq 'Yes') {
  117.     $switch = "i" . $switch;
  118.     &turnOnPort($num);
  119.     }
  120.     if ($switch) {
  121.         $cmd = &hash_modem($fld{'modem'.$num},1,3);
  122.         if ($cmd) {
  123.                 if ($switch ne "o") {
  124.                 @cmd = split(/\s+/,$cmd);
  125.                 $cmd[1] = "-".$switch;
  126.                 $cmd = join(' ',@cmd);
  127.                 }
  128.                 $cmd = "/etc/uucp/"."$cmd $num";
  129.                 system("$cmd > /dev/null 2>&1");
  130.         }
  131.     } 
  132. }
  133.  
  134. sub deleteDevice {
  135.     $doRename = 0;
  136.     open(IN,"< $confD");
  137.     open(OUT,"> $dummy");
  138.     while(<IN>) {
  139.     @items = split(/\s+/);
  140.     if ($items[0] eq "ACU" && substr($items[1],4,1) eq $_[0]) {
  141.         $doRename = 1;
  142.         print OUT "# $_";
  143.     } elsif ($items[0] eq "Direct" && substr($items[1],4,1) eq $_[0]) {
  144.         $doRename = 1;
  145.         print OUT "# $_";
  146.     } else { print OUT $_; }
  147.     }
  148.     close(IN);
  149.     close(OUT);
  150.     if ($doRename) { rename($dummy,$confD); }
  151. }
  152.  
  153. sub editDevice {
  154.     $nm = $_[0];
  155.  
  156.     $found = 0;
  157.     open(IN,"< $confD");
  158.     open(OUT,"> $dummy");
  159.     while(<IN>) {
  160.     $line = $_;
  161.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  162.     $line =~ /^\s*(.*)$/;
  163.     $line1 = $1;
  164.     @items = split(/ /,$line1);
  165.     if ($items[0] eq "Direct" && $items[1] eq "ttyd".$nm) { 
  166.         print OUT "# $line";
  167.         if ($found == 0) {
  168.         $found = 1;
  169.         $mdm = &hash_modem($fld{'modem'.$nm},1,0);
  170.         if ($fld{'speed'.$nm} < 9600) { $dev = "ttym".$nm; }
  171.         else { $dev = "ttyf".$nm; }
  172.         print OUT "ACU $dev null $fld{'speed'.$nm} 212 x $mdm\n";
  173.         print OUT "Direct ttyd",$nm," - $fld{'speed'.$nm} direct\n";
  174.         }
  175.     } elsif ($items[0] eq "ACU" && substr($items[1],4,1) eq $nm) {
  176.         print OUT "# $line";
  177.     } else { print OUT $line; }
  178.     }
  179.     if ($found == 0) {
  180.     $mdm = &hash_modem($fld{'modem'.$nm},1,0);
  181.     if ($fld{'speed'.$nm} < 9600) { $dev = "ttym".$nm; }
  182.     else { $dev = "ttyf".$nm; }
  183.     print OUT "ACU $dev null $fld{'speed'.$nm} 212 x $mdm\n";
  184.     print OUT "Direct ttyd",$nm," - $fld{'speed'.$nm} direct\n";
  185.     }
  186.     close(OUT);
  187.     close(IN);
  188.     rename($dummy,$confD);
  189. }
  190.     
  191.  
  192. sub turnOffPort {
  193.     $nm = $_[0];
  194.     
  195.     open(IN,"< $confI");
  196.     open(OUT,"> $dummy");
  197.     while(<IN>) {
  198.     $line = $_;
  199.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  200.     $line =~ /^\s*(.*)$/;
  201.     $line1 = $1;
  202.     @items = split(/:/,$line1);
  203.     if ($items[0] eq "t".$nm) { 
  204.         splice(@items,2,1,"off");
  205.         $line = join(':',@items);
  206.         print OUT "$line\n"; 
  207.     }
  208.     else { print OUT $line; }
  209.     }
  210.     close(IN);
  211.     close(OUT);
  212.     rename($dummy,$confI);
  213. }
  214.  
  215. sub turnOnPort {
  216.     $nm = $_[0];
  217.     $found = 0;
  218.     open(IN,"< $confI");
  219.     open(OUT,"> $dummy");
  220.     while(<IN>) {
  221.         @items = split(/:/);
  222.         if ($items[0] eq "t".$nm) {
  223.             $iArg = &hash_modem($fld{'modem'.$nm},1,2);
  224.             print OUT "t$nm",":23:respawn:/usr/lib/uucp/uugetty ";
  225.             print OUT "-Nt60 -i$iArg",",conn ttyf$nm dx_38400\n";
  226.             $found = 1;
  227.         }
  228.         else { print OUT $_; }
  229.     }
  230.     if ($found == 0) {
  231.         $iArg = &hash_modem($fld{'modem'.$nm},1,2);
  232.         print OUT "t$nm:23:respawn:/usr/lib/uucp/uugetty ";
  233.         print OUT "-Nt60 -i$iArg ttyf$nm dx_38400\n";
  234.     }
  235.     close(IN);
  236.     close(OUT);
  237.     rename($dummy,$confI);
  238. }
  239.     
  240. sub getCurrentStatus {
  241.     $di[0] = 0; $di[1] = 0;
  242.     $do[0] = 0; $do[1] = 0;
  243.     open(IN,"< $confI");
  244.     while(<IN>) {
  245.     @items = split(/\s+/);
  246.     @terms = split(/:/,$items[0]);
  247.     if ($terms[0] eq "t1") {
  248.         if ($terms[2] ne "off") { 
  249.         $di[0] = 1;
  250.         $items[2] =~ /-i(.*)\,conn/;
  251.         $modem1 = &hash_modem($1,2,1); 
  252.         }
  253.     }
  254.     if ($terms[0] eq "t2") {
  255.         if ($terms[2] ne "off") { 
  256.         $di[1] = 1; 
  257.         $items[2] =~ /-i(.*)\,conn/;
  258.         $modem2 = &hash_modem($1,2,1); 
  259.         }
  260.     }
  261.     }
  262.     close(IN);
  263.  
  264.     open(IN,"< $confD");
  265.     while(<IN>) {
  266.     @items = split(/\s+/);
  267.     if ($items[0] eq "ACU") {
  268.         $char = substr($items[1],4,1);
  269.         if ($char eq "1") {
  270.         $do[0] = 1;
  271.         $modem1 = &hash_modem($items[6],0,1);
  272.         $speed1 = $items[3];
  273.         }
  274.         if ($char eq "2") {
  275.         $do[1] = 1;
  276.         $modem2 = &hash_modem($items[6],0,1);
  277.         $speed2 = $items[3];
  278.         }
  279.     }
  280.     }
  281.     close(IN);
  282.     
  283.     $val{'dial_in1'} = $di[0] ? 'Yes' : 'No';
  284.     $val{'dial_in2'} = $di[1] ? 'Yes' : 'No';
  285.     $val{'dial_out1'} = $do[0] ? 'Yes' : 'No';
  286.     $val{'dial_out2'} = $do[1] ? 'Yes' : 'No';
  287.  
  288.     if ($speed1 eq "") { $speed1 = "9600"; }
  289.     if ($speed2 eq "") { $speed2 = "9600"; }
  290.     if ($modem1 eq "") { $modem1 = "Hayes smartmodem"; }
  291.     if ($modem2 eq "") { $modem2 = "Hayes smartmodem"; }
  292.     
  293. sub generic {
  294.     print "<form action=$myname method=post>";
  295.  
  296.     &header_block($title);
  297.  
  298.     print "<i>$message</i>";
  299.  
  300.     print "<center><table cellpadding=5 width=450>";
  301.  
  302.     print "<tr><th></th><th align=left>Port 1</th><th align=left>Port 2</th></tr>";
  303.  
  304.     print "<tr><th align=left>Reconfigure:</th><td align=left>",
  305.       &radio('enable1','No','Yes','No'),
  306.       "</td><td align=left>",
  307.       &radio('enable2','No','Yes','No'),"</td></tr>";
  308.  
  309.     print "<tr><th align=left>Allow users to dial in:<td align=left>",
  310.         &radio('dial_in1',$val{'dial_in1'},'Yes','No'),"</td><td>",
  311.         &radio('dial_in2',$val{'dial_in2'},'Yes','No'),"</td></tr>";
  312.  
  313.     print "<tr><th align=left>Allow users to dial out:<td align=left>",
  314.         &radio('dial_out1',$val{'dial_out1'},'Yes','No'),"</td><td>",
  315.         &radio('dial_out2',$val{'dial_out2'},'Yes','No'),"</td></tr>";
  316.  
  317.     print "<tr><th align=left>Modem model:</th><td align=left>",
  318.       &select_list('modem1',$modem1,*modemList), "</td>";
  319.  
  320.     print "<td align=left>",&select_list('modem2',$modem2,*modemList),"</td></tr>";
  321.  
  322.     print "<tr><th align=left>Baud rate:</th><td align=left>",
  323.       &select('speed1',$speed1,
  324.         '2400',
  325.         '9600',
  326.         '14400',
  327.         '19200',
  328.         '28800',
  329.         '38400'), "</td>";
  330.     print "<td align=left>",&select('speed2',$speed2,
  331.         '2400',
  332.         '9600',
  333.         '14400',
  334.         '19200',
  335.         '28800',
  336.         '38400'), "</td></tr>";
  337.  
  338.     print '</table></center><br>';
  339.  
  340.     print &buttons('doit','Ok');
  341.  
  342.     print '</form></body></html>';
  343. }
  344.  
  345.